package written.test;

import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;

/**
 * @author dangqi
 * @date 2021/7/31 19:48
 */
public class YuanFuDao2 {
    //[]3[]3[[[]2]3][[[]3[]2]]
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = "#";
        while (!(s = sc.nextLine()).equals("#")){
            System.out.println(calNum(s));
        }
    }
    public static int calNum(String s){
        int tmp = 0;
        Deque<Integer> stack = new LinkedList<>();
        Deque<Integer> res = new LinkedList<>();
        int ans = 0;
        for(int i = s.length() - 1; i >= 0; i--){
            if(Character.isDigit(s.charAt(i))){
                stack.push(s.charAt(i) - '0');
            }else if(s.charAt(i) == ']'){
                if(i>=s.length()-1 || !Character.isDigit(s.charAt(i+1))){
                    stack.push(1);
                }
                if(!stack.isEmpty()) res.push(tmp);
                else ans += tmp;
                tmp = 0;
            }else if(s.charAt(i) == '['){
                if(s.charAt(i+1)=='['){
                    tmp = getSum(res)  + tmp;
                }
                tmp = tmp * stack.peek() + stack.pop();
            }
        }
        res.push(tmp);

        return ans + getSum(res);
    }
    public static int getSum(Deque<Integer> res){
        int r = 0;
        while (!res.isEmpty()){
            r += res.pop();
        }
        return r;
    }
}
